
<?php $this->countries->buffer();if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=""){?>
<div class="col-md-8">
<div class="main-content" id="main-content">
		<div class="sub-content">
			<div class="top-header page-header clearfix">
				<h1>User Profile</h1>
			</div>
			<div class="top-links">
				<ul class="form-progress-bar">
					<? if(isset($_GET['edit']) && $_GET['edit']!=""){?>
						<li class="active-menu step-no"><a href="<? echo $this->Url('users')?>/adduser?user_id=<? echo $_GET['user_id'];?>&edit=1"><span>1</span></a></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>2</span></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>3</span></li>
					<?}else if(isset($_GET['user_id']) && $_GET['user_id']!=""){?>
						<li class="step-no active-menu"><a href="<? echo $this->Url('users')?>/adduser?user_id=<? echo $_GET['user_id'];?>"><span>1</span></a></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>2</span></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>3</span></li>
					<?}else{?>
						<li class="active-menu step-no"><a href="<? echo $this->Url('users')?>/adduser"><span>1</span></a></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>2</span></li>
						<li class="indicator"><span></span></li>
						<li class="step-no"><span>3</span></li>
					<?}?>	
				</ul>
			</div>
		<div class="user-profile1 col-md-12">
				<form id="signupForm" name="signupForm"  method="post" class="form-horizontal" role="form">
					<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=="superadmin"){?>
							<div class="form-group">
								<label class="control-label col-sm-3">Admins</label>
								<div class="col-sm-9">
								<div class="select_6">
									
									<select id="admin_users" name="admin_users" onchange="getUsers( this.value );" class="form-control">
										<option value="">-Select a admin</option>
										<? if(isset($this->getalladmins) && count($this->getalladmins)){ foreach($this->getalladmins as $admins){?>
											<? if( (isset($this->user_details->parent_user_id) && $this->user_details->parent_user_id==$admins->user_id) && ! isset($_SESSION['usersinfo']['adminuser_user_id']) ){?>
												<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>" selected="selected"><? echo $admins->company_name;?></option>
											<?}else if( isset($_SESSION['usersinfo']['adminuser_user_id']) && $_SESSION['usersinfo']['adminuser_user_id']==$admins->user_id ){?>	
												<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>" selected="selected"><? echo $admins->company_name;?></option>		
											<?}else{?>
												<option value="<? echo $admins->user_id.'/'.$admins->company_name;?>"><? echo $admins->company_name;?></option>		
											<?}?>
										<?}}?>										
									</select>
								</div></div>
							</div><span style="color:red" id="erroradmin"></span>
					<?}?>
						<div class="form-group">
							<label class="control-label col-sm-3">Company Name</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['cname'])){?>
								<input  type="text" id="cname" name="cname" class="form-control"  value="<? echo $_SESSION['usersinfo']['cname'];?>" placeholder="Company Name"> 
							<?}else if(isset($this->user_details->company_name)){?>
							<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
								<input  type="text" id="cname" name="cname" class="form-control" value="<? echo $this->user_details->company_name;?>" placeholder="Company Name"> 
							<?}else{?>
								<input  type="text" id="cname" name="cname" class="form-control" readonly="readonly" value="<? echo $this->user_details->company_name;?>" placeholder="Company Name"> 
							<?}}else{?>
							<input  type="text" id="cname" name="cname" class="form-control" value="" placeholder="Company Name"> 
							<?}?>
							</div>
						</div><span style="color:red" id="errorcname"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Country</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin'){?>							
								<div class="select_6">
									<select name="country" id="country" onChange="Javascript:getCountryIndustries( this.value );" class="form-control">
									    <option value="">-Select a country</option>	
										<?php if(isset($this->getRegions) && count($this->getRegions)>0){foreach($this->getRegions as $regions){										
										if($_SESSION['usersinfo']['country']==$regions->country_id){?>
										  <option value="<? echo $regions->country_id.'-'.$regions->countryNicename;?>" selected="selected"><? echo $regions->countryNicename;?></option>
										<?}else if($this->user_details->country==$regions->country_id && ! isset($_SESSION['usersinfo']['country']) ){?>
											<option value="<? echo $regions->country_id.'-'.$regions->countryNicename;?>" selected="selected"><? echo $regions->countryNicename;?></option> 
										<?}else{?>
											<option value="<? echo $regions->country_id.'-'.$regions->countryNicename;?>"><? echo $regions->countryNicename;?></option> 
										<?}}}?>	
									</select>
								</div>							
							<?}else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='superadmin'){?>
								<div class="select_6">
									<select name="country" id="country" onChange="Javascript:getCountryIndustries( this.value );" class="form-control">
									    <option value="">-Select a country</option>											
									</select>
								</div>		
							<?}?></div>
						</div><span id="errorcountry" style='color:red';></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Industry</label>
							<div class="col-sm-9">
							<div class="select_6">
							<? if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='admin'){?>
								<select id="industry" name="industry" class="form-control">
									<option value="">-Select a industry</option>
										<?php if(isset($this->getallindustries) && count($this->getallindustries)>0){foreach($this->getallindustries as $adminIndustries){										
										if(isset($_SESSION['usersinfo']['industry']) && $_SESSION['usersinfo']['industry']==$adminIndustries->industry_id){?>
											 <option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>" selected="selected"><? echo $adminIndustries->industryNicename;?></option>
										<?}else if($this->user_details->industry==$adminIndustries->industry_id){?>
											<option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>" selected="selected"><? echo $adminIndustries->industryNicename;?></option> 
										<?}else{?>
											<!--<option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>"><? echo $adminIndustries->industryNicename;?></option>-->
										<?}}}?>									
								</select>
							<?}else if(isset($_SESSION['user']['user_type']) && $_SESSION['user']['user_type']=='superadmin'){?>
								<select id="industry" name="industry" class="form-control">
									<option value="">Select a industry</option>
									<?php if(isset($this->getallindustries) && count($this->getallindustries)>0){foreach($this->getallindustries as $adminIndustries){										
										if(isset($_SESSION['usersinfo']['industry']) && $_SESSION['usersinfo']['industry']==$adminIndustries->industry_id){?>
											 <option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>" selected="selected"><? echo $adminIndustries->industryNicename;?></option>
										<?}else if($this->user_details->industry==$adminIndustries->industry_id){?>
											<option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>" selected="selected"><? echo $adminIndustries->industryNicename;?></option> 
										<?}else{?>
											<!--<option value="<? echo $adminIndustries->industry_id.'/'.$adminIndustries->industryNicename;?>"><? echo $adminIndustries->industryNicename;?></option>-->
										<?}}}?>	
								</select>
							<?}?>
							</div></div>					
						</div><span style="color:red" id="errorindustry"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Address 1</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address1'])){?>
								<textarea  class="profile_add form-control" id="address1" name="address1" ><? echo $_SESSION['usersinfo']['address1'];?></textarea>
							<? } else if(isset($this->user_details->address1)){
								if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea  class="profile_add form-control" id="address1"  name="address1" ><? echo $this->user_details->address1;?></textarea>
								<?}else{?>	
									<textarea  class="profile_add form-control" id="address1" readonly="readonly" name="address1" ><? echo $this->user_details->address1;?></textarea>
							<?}}else{?>
								<textarea  class="profile_add form-control" id="address1" name="address1" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress1"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Address 2</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address2'])){?>
								<textarea  class="profile_add form-control" id="address2" name="address2" ><? echo $_SESSION['usersinfo']['address2'];?></textarea>
							<?}else if(isset($this->user_details->address2)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea class="profile_add form-control" id="address2" name="address2" ><? echo $this->user_details->address2;?></textarea>
								<?}else{?>
									<textarea class="profile_add form-control" id="address2" name="address2"   readonly="readonly" ><? echo $this->user_details->address2;?></textarea>
							<?}}else{?>
									<textarea  class="profile_add form-control" id="address2" name="address2" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress2"></span>
						<div class="form-group ">
							<label class="control-label col-sm-3">Address 3</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['address3'])){?>
								<textarea  class="profile_add form-control" id="address3" name="address3"   ><? echo $_SESSION['usersinfo']['address3'];?></textarea>
							<?}else if(isset($this->user_details->address3)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<textarea  class="profile_add form-control" id="address3" name="address3" ><? echo $this->user_details->address3;?></textarea>
								<?}else{?>
									<textarea  class="profile_add form-control" id="address3" name="address3"  readonly="readonly" ><? echo $this->user_details->address3;?></textarea>
								<?}}else{?>
								<textarea  class="profile_add form-control" id="address3" name="address3" ></textarea>
							<?}?></div>
						</div><span style="color:red" id="erroraddress3"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Landmark Near By</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['lmnear'])){?>
									<input  type="text" id="lmnear" name="lmnear"   class="form-control" value="<? echo $_SESSION['usersinfo']['lmnear'];?>" placeholder="Landmark Near By" />
							<?} else if(isset($this->user_details->landmarknearby)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="lmnear" name="lmnear" class="form-control" value="<? echo $this->user_details->landmarknearby;?>" placeholder="Landmark Near By" />
								<?}else{?>
									<input type="text" id="lmnear" name="lmnear" class="form-control"  readonly="readonly"  value="<? echo $this->user_details->landmarknearby;?>" placeholder="Landmark Near By" />
							<?}}else{?>
								<input  type="text" id="lmnear" name="lmnear" class="form-control" value="" placeholder="Landmark Near By" />
							<?}?></div>
						</div><span style="color:red" id="errorlmnear"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">City</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['city'])){?>
								<input  type="text" id="city" class="form-control" value="<? echo $_SESSION['usersinfo']['city'];?>" name="city" placeholder="Please enter city"/>
							<?}else if(isset($this->user_details->city)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="city" class="form-control" value="<? echo $this->user_details->city;?>" name="city" placeholder="Please enter city"/>
								<?}else{?>
									<input  type="text" id="city" class="form-control" readonly="readonly" value="<? echo $this->user_details->city;?>" name="city" placeholder="Please enter city"/>
							<?}}else{?>
									<input  type="text" id="city" class="form-control" value="" name="city" placeholder="Please enter city"/>
							<?}?></div>
						</div><span style="color:red" id="errorcity"></span>
						<div id="regions">
						<div class="form-group" id="currCFormsList1">
							<label class="control-label col-sm-3">Buy Area</label>
							<div class="col-sm-9">
							<?
							 if(isset($this->user_details->country) && $this->user_details->country!=""){?>
							<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
								<div class="select_6">
									<select id="region1" name="region[]" class="form-control">
									    <option value="">-Select a region</option>	
										<?php
										if(isset($this->countries) && count($this->countries)>0){foreach($this->countries as $countries){										
										if($_SESSION['usersinfo']['country']==$countries->country_id){?>
										  <option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option>
										<?}else if($this->user_details->country==$countries->country_id){?>
											<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
										<?}else{?>
											<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>"><? echo $countries->nicename;?></option> 
										<?}}}?>	
									</select>
								</div>&nbsp;<a href="javascript:void(0)" style="display:inline-block;margin-left:10px;margin-top5px;" id='curAddC' Onclick="Javascript:addRegion();">Add</a>
							<?}else{?>
							    <input type="text" readonly="readonly" class="form-control" value="<? echo $this->user_details->usercountry;?>">
								<input type="hidden" id="country" name="country" value="<? echo $this->user_details->country;?>">
							<?}}else{?>
								<div class="select_6">
									<select id="region1" name="region[]"  readonly="readonly" class="form-control">
										<option value="">-Select a region</option>	
										<?php if(isset($this->countries) && count($this->countries)>0){foreach($this->countries as $countries){										
										if(isset($_SESSION['usersinfo']['country']) && $_SESSION['usersinfo']['country']==$countries->country_id){?>
											<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>" selected="selected"><? echo $countries->nicename;?></option> 
										<?}else{?>
											<option value="<? echo $countries->country_id.'-'.$countries->nicename;?>"><? echo $countries->nicename;?></option> 
										<?}}}?>	
									</select>
								</div>&nbsp;<a href="javascript:void(0)" style="display:inline-block;margin-left:10px;margin-top5px;" id='curAddC' Onclick="Javascript:addRegion();">Add</a>
							<?}?>
						</div>	
						</div></div><span id="errorregion" style='color:red';></span>

						<div class="form-group">
							<label class="control-label col-sm-3">Email</label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['email'])){?>
								<input  type="text" id="email" name="email"class="form-control"value="<? echo $_SESSION['usersinfo']['email'];?>" placeholder="Email" />
							<?}else if(isset($this->user_details->email)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="email" name="email" class="form-control" value="<? echo $this->user_details->email;?>" placeholder="Email" />
								<?}else{?>
									<input  type="text" id="email" name="email" class="form-control" readonly="readonly" value="<? echo $this->user_details->email;?>" placeholder="Email" />
							<?}}else{?>
								<input  type="text" id="email" name="email" class="form-control" onblur="emailSucc()" value="" placeholder="Email" />
							<?}?></div>
						</div><span id="error" style="color:red"></span> 
						      <span id="emptyemail" style="color:red"></span> 
						     <span style="color:red" id="erroremail"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Phone </label>
							<div class="col-sm-9">
							<?  if(isset($_SESSION['usersinfo']['phone'])){?>
								<input  type="text" id="phone" name="phone" class="form-control" value="<? echo $_SESSION['usersinfo']['phone'];?>" placeholder="Phone" />
							<?}else if(isset($this->user_details->phone)){?>
							<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
								<input  type="text" id="phone" name="phone" class="form-control"  value="<? echo $this->user_details->phone;?>" placeholder="Phone" />
							<?}else{?>
								<input  type="text" id="phone" name="phone" class="form-control" readonly="readonly" value="<? echo $this->user_details->phone;?>" placeholder="Phone" />
							<?}}else{?>
								<input  type="text" id="phone" name="phone" class="form-control" value="" placeholder="Phone" />
							<?}?></div>							
						</div><span style="color:red" id="errorphone"></span>
						<div class="form-group">
							<label class="control-label col-sm-3">Fax </label>
							<div class="col-sm-9">
							<? if(isset($_SESSION['usersinfo']['fax'])){?>
								<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="<? echo $_SESSION['usersinfo']['fax'];?>" />
							<?}else if(isset($this->user_details->fax)){?>
								<? if(isset($_SESSION['user']['user_id']) && $_SESSION['user']['user_id']!=$this->user_details->user_id){?>
									<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="<? echo $this->user_details->fax;?>" />
								<?}else{?>
								<input  type="text" id="fax" name="fax" class="form-control"  readonly="readonly" placeholder="Fax" value="<? echo $this->user_details->fax;?>" />
	                        <?}}else{?>
								<input  type="text" id="fax" name="fax" class="form-control" placeholder="Fax" value="" />
							<?}?></div>
						</div><span style="color:red" id="errorfax"></span>

						<input type="hidden" id="sessAdminInfo" name="sessAdminInfo" value="<? if( isset($_SESSION['usersinfo']['adminuser_user_id']) && isset($_SESSION['usersinfo']['adminuser_user_name']) ){ echo $_SESSION['usersinfo']['adminuser_user_id'] . "/" . $_SESSION['usersinfo']['adminuser_user_name']; } else{ echo "";} ?><? if( isset($this->sessAdminInfo)  && ! isset($_SESSION['usersinfo']['adminuser_user_id'])){ echo $this->sessAdminInfo; } else{ echo "";} ?>" />
						<input type="hidden" id="sessCntrysId" name="sessCntrysId" value="<? if( isset($_SESSION['usersinfo']['country']) && isset($_SESSION['usersinfo']['country_name']) ){ echo $_SESSION['usersinfo']['country'] . "/" . $_SESSION['usersinfo']['country_name']; } else{ echo "";} ?><? if( isset($this->sessCntrysId)  && ! isset($_SESSION['usersinfo']['country'])){ echo $this->sessCntrysId; } else{ echo "";} ?>" />
						<input type="hidden" id="indsCntrysIds" name="indsCntrysIds" value="<? if(isset($_SESSION['usersinfo']['regionsInfo'])){ echo $_SESSION['usersinfo']['regionsInfo']; } else{ echo "";} ?><? if( isset($this->loadedRegions) && ! isset($_SESSION['usersinfo']['regionsInfo']) ){ echo $this->loadedRegions; } else{ echo "";} ?>" />
						<input type="hidden" id="indsCntrysCount" name="indsCntrysCount" value="<? if(isset($_SESSION['usersinfo']['indsCntrysCount'])){ echo $_SESSION['usersinfo']['indsCntrysCount']; } else{ echo "";} ?><? if( isset($this->existingRegionsCount) && ! isset($_SESSION['usersinfo']['indsCntrysCount']) ){ echo $this->existingRegionsCount; } else{ echo "";} ?>" />
						<input type="hidden" id="hid_user_id" name="hid_user_id" value="<? if(isset($this->user_details->user_id)){echo $this->user_details->user_id;}?>">
						<input type="hidden" id="hid_industry_id" name="hid_industry_id" value="<? if(isset($this->user_details->industry)){echo $this->user_details->industry;}?>">
						<input type="hidden" id="hid_country_id" name="hid_country_id" value="<? if(isset($this->user_details->country)){echo $this->user_details->country;}?>">
						<input type="hidden" id="exit_email" name="exit_email" value="0">
						<input type="hidden" id="edit_status" name="edit_status" value="<? if(isset($_GET['edit'])){echo $_GET['edit'];}?>">						
						<div class="form-group">
							<div class="col-sm-3">&nbsp;</div>
							<div class="col-sm-9">
							<a href="javascript:void(0)"  class="btn btn-danger" role="button" id="continue" onclick="return validate();"  />Continue</a>
							</div>
						</div>
				<div style="display:none;"><select id="currentIndustry"></select><select id="currentCountry"></select></div>
				</form>
		</div>
	</div>
</div>
</div>
<script type="text/javascript">

$( document ).ready(function()
{
	var indsCntrysCount = $("#indsCntrysCount").val().trim();
	var indsCntrysIds = $("#indsCntrysIds").val();
	
	// alert( indsCntrysCount );
	// alert( indsCntrysIds );
	var regionRows = "";
	if( indsCntrysIds != "" )
	{
		regionRows = indsCntrysIds.split( "!" );
		$("#region1").val( regionRows[0].trim() );
		
		if( $("#sessAdminInfo").val() != "")
		{
			$('#admin_users').val( $("#sessAdminInfo").val() );
		}
		if( $('#admin_users').val() != "" )
		{
			getUsers( $('#admin_users').val() );
		}
	}
	
	if( indsCntrysCount > 1 )
	{

		if( $("#curAddC") )
		{
			$("#curAddC").remove();
		}
		for( var indsCntrysOptId = 2,regionsCollectionId = 1; indsCntrysOptId <= indsCntrysCount; indsCntrysOptId++,regionsCollectionId++ )
		{
			$("#currentCountry").html( $("#region" + rc).html() );
			$("#currentCountry").val( $("#region" + rc).val() );
			$("#currentCountry option:selected").remove();
			
			rc++;
			var newCountryHtml = "<div class='form-group' id='cformsList'><label class='control-label col-sm-3'>Buy Area</label><div class='col-sm-9'><div class='select_6'>";
			newCountryHtml += "<select name='region[]' id='currCountry' class='form-control'>" + $("#currentCountry").html();
			
			// alert( newCountryHtml );
			
			if( indsCntrysOptId == indsCntrysCount )
			{
				if( $('#currentCountry > option').length > 2 )
				{
					newCountryHtml += "</select></div>" + "&nbsp;<a id='curAddC' href='javascript:void(0)' style='margin-top:5px;display:inline-block;margin-left:10px;' Onclick='Javascript:addRegion();'>Add</a><a id='curDelC' href='javascript:void(0)' style='margin-top:5px;display:inline-block;margin-left:10px;'Onclick='Javascript:delCurrRegion();'>Delete</a></div></div>";
				}
				else
				{
					newCountryHtml += "</select></div>" + "<a href='javascript:void(0)' id='curDelC' style='margin-top:5px;display:inline-block;margin-left:10px;' Onclick='Javascript:delCurrRegion();'>Delete</a></div></div>";
				}
			}

			// $("#regions").html( $("#regions").html() + newCountryHtml );
			$("#regions").append( newCountryHtml );
			
			$("#cformsList").attr( "id","currCFormsList" + rc );

			$("#currCountry").attr( "id","region" + rc );
			
			if( indsCntrysIds != "" )
			{
				$("#region" + rc).val( regionRows[regionsCollectionId].trim() );
			}
			// alert ( $("#region" + rc).val() );
		}
		// alert( rc );
	}
});

var rc = 1;

function addRegion()
{
	// alert($("#region" + rc));
	if( $("#region" + rc).val() == 0 )
	{
		alert( "Please select region" );
		return false;
	}

	if( $("#curAddC").length == 1 )
	{
		$("#curAddC").remove();
	}

	if( $("#curDelC").length == 1 )
	{
		$("#curDelC").remove();
	}
	
	$("#currentCountry").html( $("#region" + rc).html() );
	$("#currentCountry").val( $("#region" + rc).val() );
	$("#currentCountry option:selected").remove();
	
	rc++;
	var newCountryHtml = "<div class='form-group' id='cformsList'><label class='control-label col-sm-3'>Buy Area</label><div class='col-sm-9'><div class='select_6'>";
	newCountryHtml += "<select name='region[]' id='currCountry' class='form-control'>" + $("#currentCountry").html();
	
	if( $('#currentCountry > option').length > 2 )
	{
		newCountryHtml += "</select></div>" + "&nbsp;<a id='curAddC' href='javascript:void(0)' Onclick='Javascript:addRegion();' style='margin-top:5px;display:inline-block;margin-left:10px;'>Add</a><a id='curDelC' href='javascript:void(0)' style='margin-top:5px;display:inline-block;margin-left:10px;' Onclick='Javascript:delCurrRegion();'>Delete</a></div></div>";
	}
	else
	{
		newCountryHtml += "</select></div>" + "<a href='javascript:void(0)' id='curDelC' style='margin-top:5px;display:inline-block;margin-left:10px;' Onclick='Javascript:delCurrRegion();'>Delete</a></div></div>";
	}
	
	// alert( newCountryHtml );
	
	// $("#regions").html( $("#regions").html() + newCountryHtml );
	$("#regions").append( newCountryHtml );
	
	$("#cformsList").attr( "id","currCFormsList" + rc );

	$("#currCountry").attr( "id","region" + rc );
	
	$("#region" + rc).val( "" );
	// alert ( $("#region" + rc).val() );
}

// function to delete the newly added set of elements
function delCurrRegion()
{
	$("#currCFormsList" + rc).remove();
	rc--;
	
	if( $("#curDelC").length == 1 )
	{
		$("#curDelC").remove();
	}
	// alert( $("#currCFormsList" + rc).html() );
	
	$("#currCFormsList" + rc +" .col-sm-9").append( "<a href='javascript:void(0)' id='curAddC' Onclick='Javascript:addRegion();' style='margin-top:5px;display:inline-block;margin-left:10px;'>Add</a></div>" );
	
	if( rc > 1 )
	{
		$("#currCFormsList" + rc +" .col-sm-9").append( "<a href='javascript:void(0)' id='curDelC' style='margin-top:5px;display:inline-block;margin-left:10px;' Onclick='Javascript:delCurrRegion();'>Delete</a></div>" )
	}
}


	function validate(){
		var count=0;
	    var flag=true;	
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var letters = /^[a-zA-Z ]*$/;
       //var valid1 = /^[0-9]+$/;        
		var validpattern = /^[+-]?\d+$/;
		//var valid3=/^[\d\s() -]+$/;
		var admin_users=$('#admin_users').val();
		var companyname=$('#cname').val();
		var industry=$('#industry').val();
		var address1=$('#address1').val();
		var address2=$('#address2').val();
		var address3=$('#address3').val();
		var landmarknearby=$('#lmnear').val();
		var city=$('#city').val();
		var country=$('#country').val();
		var emailcheck=$('#email').val();
		var pnumber=$('#phone').val();
		var fax=$('#fax').val();
		var exit_email=$("#exit_email").val();
		if(admin_users==""){		
			$('#erroradmin').html('*Admin is required');	
			flag=false;
		}else{
			$('#errorcname').html('');
		}
		if(companyname==""){
			$('#errorcname').html('*Company name is required');	
			flag=false;
		}else{
			$('#errorcname').html('');
		}
		if(industry==""){
			$('#errorindustry').html('*Industry is required');	
			flag=false;
		}else{
			$('#errorindustry').html('');
		}
		if(address1==""){
			$('#erroraddress1').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress1').html('');
		}
		if(address2==""){
			$('#erroraddress2').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress2').html('');
		}
        if(address3==""){
			$('#erroraddress3').html('*Address filed is required');
			flag=false;
		}else{
			 $('#erroraddress3').html('');
		}
		if(landmarknearby==""){
			$('#errorlmnear').html('*Land mark near by is required');	
			flag=false;
		}else{
			$('#errorlmnear').html('');
		}
		if(city==""){
			$('#errorcity').html('*City is required');
			flag=false;
		}else{
			$('#errorcity').html('');
		}
		if(country==""){
			$('#errorcountry').html('*Country required');
			flag=false;
		}else{
			$('#errorcountry').html('');
		}
	
		var regionSelected = true;
		for( var regionId = 1; regionId <= rc; regionId++ )
		{
			if( $("#region" + regionId).val() == "" )
			{
				$('#errorregion').html('*Region required');
				flag=false;
				regionSelected = false;
			}
		}
		
		var regionsCollection = "";
		for( var regionId = 1; regionId <= rc; regionId++ )
		{
			regionsCollection += $("#region" + regionId).val() + "!";
		}
		regionsCollection = regionsCollection.substring(0, (regionsCollection.length-1));
		
		var unique_values={};
		var regionsArray=regionsCollection.split('!');
		for(var i=0;i<regionsArray.length;i++){
			 if ( ! unique_values[regionsArray[i]] ) {
			   unique_values[regionsArray[i]] = true;
			   } else {
				   alert('Regions should be unique');
				   flag=false;
			   }
		}
		if( regionSelected )
		{
			$('#errorregion').html('');
		}
		if(emailcheck==""){
		  $('#erroremail').html('*User email is required');
		  flag=false;
		}else if(!filter.test(emailcheck)){
		  $('#erroremail').html('Email format is not correct');
		  $("#error").html("");
		  flag=false;
		}else if(exit_email=='1'){
			$('#erroremail').html('');
			 $("#error").html("User is already exits");
			flag=false;
		}else{
		   $('#erroremail').html('');
		}
		if(pnumber==""){
		  $('#errorphone').html('*Phone number is required');
		  flag=false;
		}else if(!pnumber.match(validpattern)){
		     $('#errorphone').html('*Invalid phone number');
			   flag=false;
		}else{
		 $('#errorphone').html('');
		}
		if(fax==""){
			$('#errorfax').html('*Fax is required');	
			flag=false;
		}else if(isNaN(fax)){
		    $('#errorfax').html('Numbers only');
			flag=false;
		}else{
			$('#errorfax').html('');
		}

		var combinations = "";
		
		if(flag==false){
			return false;
		}else{
			$('#indsCntrysCount').val( rc );
			$('#indsCntrysIds').val( regionsCollection );
			$("#signupForm").submit();
		}
	}
	function emailSucc(){
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		flag=true;
		  var emailcheck=$('#email').val();
		   if(emailcheck==""){
		     $('#erroremail').html('*User email is required');
			 flag=false;
		   }else if(!filter.test(emailcheck)){
			$('#erroremail').html('Email format is not correct');
			$("#error").html("");
			flag=false;
			}
			if(flag==false){ 
				return false;
			}else{
				   $.ajax({
					url:BASE_PATH+"/users/checkregemail",
					type:"POST",
					data:{email:emailcheck},
					success: function(data){
					 if(data.output=='success'){
						$("#exit_email").val('1');
						$('#erroremail').html('');
						$("#error").html("User is already exits");			 
						}else{
							$("#exit_email").val('0');
							$("#error").html("");
							$('#erroremail').html('');
						}
					},
				});
			}
   }

   function getCountryIndustries( country_id ){
		if(country_id!=''){			
			if($("#admin_users").length == 1 ){
				if( $("#admin_users").val() == "" )
				{
					$('#country').html( "<option value=''>Select a country</option>" );
					$('#industry').html( "<option value=''>Select a industry</option>" );
					return false;
				}
				var adminInfo=$("#admin_users").val().split( "/" );
				var admin_user_id=adminInfo[0];
			}else{
				var admin_user_id='<? echo $_SESSION['user']['user_id'] ?>';
			}
			if($("#hid_industry_id").val()!=''){
				var industry_id=$("#hid_industry_id").val();
			}else{
				var industry_id='';
			}
			
			// alert( admin_user_id );

			 $.ajax({
				url:BASE_PATH+"/users/get-admin-country-industries",
				type:"POST",
				data:{admin_user_id:admin_user_id,industry_id:industry_id,country_id:country_id},
				success: function(data){
					if(data.output=='success'){
						$('#industry').html(data.industires);
					}else if(data.output=='notsuccess'){
						$('#industry').html(data.industires);
					}
				},
			});
		}
		else
		{
			$('#industry').html( "<option value=''>Select a industry</option>" );
		}

	}

   function getUsers(admin_user_id){
		if(admin_user_id!=''){
			if( typeof admin_user_id ==="undefined" )
			{
				admin_user_id='<? echo $_SESSION['user']['user_id'] ?>';
			}
			
			if($("#hid_industry_id").val()!=''){
				var industry_id=$("#hid_industry_id").val();
			}else{
				var industry_id='';
			}
			if($("#hid_country_id").val()!=''){
				var country_id=$("#hid_country_id").val();
			}else{
				var country_id='';
			}
			// alert( "#" + admin_user_id + "#" );
			 $.ajax({
				url:BASE_PATH+"/users/get-countires-industries",
				type:"POST",
				data:{admin_user_id:admin_user_id,industry_id:industry_id,country_id:country_id},
				success: function(data){
					if(data.output=='success'){
						$('#country').html(data.countries);
						if( $("#sessCntrysId").val() != "")
						{
							$('#country').val( $("#sessCntrysId").val() );
						}
						getCountryIndustries( $('#country').val() );
						// $('#industry').html(data.industires);
					}else if(data.output=='notsuccess'){
						$('#country').html(data.countries);
						// $('#industry').html(data.industires);
					}
				},
			});
		}
		else
		{
			$('#country').html( "<option value=''>Select a country</option>" );
			$('#industry').html( "<option value=''>Select a industry</option>" );
		}

	}
</script>
<?php }else{?>
<script>
	window.location='<? echo $this->Url('home')?>';
</script>
<?php }?>
	

        